package com.example.messagemodule.adapter;

import android.Manifest;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.examination.mlib.bean.BaseBean;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.constants.AllStringConstants;
import com.examination.mlib.constants.KitArouterConstants;
import com.examination.mlib.constants.PatientUrl;
import com.examination.mlib.constants.ProjectConfigure;
import com.examination.mlib.manager.PermissionManager;
import com.example.messagemodule.R;
import com.example.messagemodule.entity.ChargeEntity;
import com.example.messagemodule.entity.ChatGroupPrescriptionStatusBean;
import com.example.messagemodule.entity.CheckVideoStartEntity;
import com.example.messagemodule.entity.GiftEntity;
import com.example.messagemodule.entity.HbasePatientImManagerEntity;
import com.example.messagemodule.entity.MessageEtpConsultingDrugsEntity;
import com.example.messagemodule.entity.VideoStatusBean;
import com.example.messagemodule.listener.EventBusMessageWrap;
import com.example.messagemodule.listener.MessageListenerType;
import com.example.messagemodule.utils.MessageUtils;
import com.example.messagemodule.widget.MessageBackgroundLeft;
import com.example.messagemodule.widget.MessageBackgroundRight;
import com.google.gson.Gson;
import com.hyphenate.chat.EMCustomMessageBody;
import com.hyphenate.chat.EMImageMessageBody;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMTextMessageBody;
import com.hyphenate.chat.EMVoiceMessageBody;
import com.examination.mlib.interfaceapi.MessageCallApi;
import com.examination.mlib.interfaceapi.NetWorkCallBack;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.https.HttpCallBack;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.network.https.interceptor.NetWorkUtils;
import com.yilijk.base.utils.ALog;
import com.yilijk.base.utils.ClickUtils;
import com.yilijk.base.utils.CommonUtils;
import com.yilijk.base.utils.DataUtils;
import com.yilijk.base.utils.DevicesUtils;
import com.yilijk.base.utils.LoadingUtils;
import com.yilijk.base.utils.ToastUtils;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ConversationMessageAdapter extends BaseMultiItemQuickAdapter<HbasePatientImManagerEntity.DataBean, BaseViewHolder> {

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */

    public static ArrayList<Integer> chargesIds = new ArrayList<>();
    public static boolean isInquiryRecord = false;
    public String startTime_description = "";
    public String endTime_description = "";
    public String relevantDateStr = "";
    public String callPhone = "";
    private PrescriptionBean.DataBean prescriptiondata;
    private ChatGroupPrescriptionStatusBean.DataBean chatprescriptiondata;
    private ChargeEntity chargeEntity;

    public void setChargeEntity(ChargeEntity chargeEntity) {
        this.chargeEntity = chargeEntity;
    }

    public ConversationMessageAdapter(List<HbasePatientImManagerEntity.DataBean> data) {
        super(data);
        //文本
        addItemType(-999, R.layout.message_inquiry_start);
        addItemType(999, R.layout.message_inquiry_end);
        addItemType(0, R.layout.message_hint_null);
//        addItemType(0, R.layout.message_hint_center);
        addItemType(1000, R.layout.message_text_left);
        addItemType(1001, R.layout.message_text_right);
        addItemType(1010, R.layout.message_text_doctor_helper_left);
//        //图片
        addItemType(2000, R.layout.message_image_left);
        addItemType(2001, R.layout.message_image_right);
////        视频
//        addItemType(30, R.layout.message_image_left);
//        addItemType(31, R.layout.message_image_right);
//        //位置
//        addItemType(40, R.layout.message_text_right);
//        addItemType(41, R.layout.message_text_right);
//        //语音
        addItemType(5000, R.layout.message_voice_left);
        addItemType(5001, R.layout.message_voice_right);
//        //文件
//        addItemType(61, R.layout.message_text_right);
//        addItemType(60, R.layout.message_text_right);
//        //cmd
//        addItemType(71, R.layout.message_cmd_right);
//        addItemType(70, R.layout.message_cmd_left);
//        addItemType(8020, R.layout.message_evaluate_left);    
//        addItemType(8021, R.layout.message_evaluate_right);
//        addItemType(8030, R.layout.message_description_left);
        addItemType(7001, R.layout.message_description_right);
        addItemType(7002, R.layout.message_received);
        addItemType(7003, R.layout.message_prescription_left);
        addItemType(7004, R.layout.message_finish);
        addItemType(7005, R.layout.message_evaluate_left);
        addItemType(7006, R.layout.message_stoptemplate);
        addItemType(7007, R.layout.message_doctor_helper_left);
        addItemType(7008, R.layout.message_patient_evaluate_finish);
        addItemType(7009, R.layout.message_text_left);
        addItemType(7010, R.layout.message_setting_phone_time);
        addItemType(7011, R.layout.message_sf_finish);
        addItemType(7012, R.layout.message_sf_submit);
        addItemType(7013, R.layout.message_cancel_auto_call);
        addItemType(7014, R.layout.message_update_phone_time);
        addItemType(7015, R.layout.message_miss_phone_call);
        addItemType(7016, R.layout.message_phone_call_end);
        addItemType(7017, R.layout.message_refund);
        addItemType(7018, R.layout.message_delay_charges);
        addItemType(7019, R.layout.message_start_video);
        addItemType(7020, R.layout.message_video_left);
        addItemType(7021, R.layout.message_video_right);
        addItemType(7022, R.layout.message_video_right);
        addItemType(7023, R.layout.message_video_right);
        addItemType(7024, R.layout.message_video_left);
        addItemType(7025, R.layout.message_etp_consulting_drugs);
        addItemType(7026, R.layout.message_hint_center);
        addItemType(7027, R.layout.message_hint_center);
        addItemType(7028, R.layout.message_patient_end_charges);
    }

    @Override
    protected void convert(BaseViewHolder helper, HbasePatientImManagerEntity.DataBean item) {
        int itemViewType = helper.getItemViewType();
//        Log.e("convert: ", item.getItemType() + "");
        helper.setVisible(R.id.message_time, item.isShowTime());
        helper.setText(R.id.message_time, item.getSendTime());


        switch (itemViewType) {
            case -999:
                if (item.getEmMessage() != null) {
                    EMTextMessageBody body_999 = (EMTextMessageBody) item.getEmMessage().getBody();
                    helper.setText(R.id.message_inquiry_start, body_999.getMessage());
                }
                break;
            case 999:
                if (item.getEmMessage() != null) {
                    EMTextMessageBody body999 = (EMTextMessageBody) item.getEmMessage().getBody();
                    helper.setText(R.id.message_inquiry_end, body999.getMessage());
                }
                break;
            case 1000:
                //对方文本消息
                if (item.getEmMessage() == null) {
                    String s = CommonUtils.decodeUTF8(item.getContent());
                    helper.setText(R.id.message_text_left_content, s);
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_text_left_img));
                } else {
                    EMTextMessageBody body_left = (EMTextMessageBody) item.getEmMessage().getBody();
                    String s = CommonUtils.decodeUTF8(body_left.getMessage());
                    helper.setText(R.id.message_text_left_content, s);
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_text_left_img));
                }
                break;
            case 1010:
                if (isInquiryRecord) {
                    helper.setVisible(R.id.doctor_helper, false);
                    if (item.getExt() != null) {
                        String customExt = item.getExt();
                        try {
                            JSONObject jsonObject = new JSONObject(customExt);
                            if (jsonObject.has("templateExt")) {
                                String templateExt = jsonObject.getString("templateExt");
                                JSONObject templateExtJsonObject = new JSONObject(templateExt);
                                if (templateExtJsonObject.has("first")) {
                                    if (templateExtJsonObject.getBoolean("first")) {
                                        helper.setVisible(R.id.message_text_left_hint, true);
                                        helper.setText(R.id.message_text_left_hint, "温馨提示：为了让医生更详细的了解您的病情，请您花费几分钟的时间，认真填写以下问题。");
                                    } else {
                                        helper.setVisible(R.id.message_text_left_hint, false);
                                    }
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    helper.setVisible(R.id.message_text_left_hint, false);
                    helper.setVisible(R.id.doctor_helper, true);
                }
                //对方文本消息
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_text_left_content, item.getContent());
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_text_left_img));
                    helper.setText(R.id.message_doctor_helper_left_content, "为了让医生更详细的了解您的病情，请您花费几分钟的时间，认真填写以下问题。");
                    helper.setVisible(R.id.message_doctor_helper_left_name, true);
                } else {
                    EMTextMessageBody body_left1 = (EMTextMessageBody) item.getEmMessage().getBody();
                    helper.setText(R.id.message_text_left_content, body_left1.getMessage());
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_text_left_img));
                    helper.setText(R.id.message_doctor_helper_left_content, "为了医生让更详细的了解您的病情，请您花费几分钟的时间，认真填写以下问题。");
                    helper.setVisible(R.id.message_doctor_helper_left_name, true);
                }
                break;
            case 1001:
                //自己文本消息
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_text_right_content, item.getContent());
                    Glide.with(mContext)
                            .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_text_right_img));
                } else {
                    EMTextMessageBody body_right = (EMTextMessageBody) item.getEmMessage().getBody();
                    helper.setText(R.id.message_text_right_content, body_right.getMessage());
                    Glide.with(mContext)
                            .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_text_right_img));
                }
                break;
            case 2000:
                helper.addOnClickListener(R.id.message_image_left_content);
                if (item.getEmMessage() == null) {
                    Glide.with(mContext).load(item.getFileUrl())
                            .transform(new CenterCrop())
                            .listener(new RequestListener<Drawable>() {
                                @Override
                                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                                    return false;
                                }

                                @Override
                                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                                    return false;
                                }
                            })
                            .into((ImageView) helper.getView(R.id.message_image_left_content));
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_image_left_img));
                } else {
                    EMImageMessageBody imageMessageBody_left = (EMImageMessageBody) item.getEmMessage().getBody();
                    Glide.with(mContext).load(imageMessageBody_left.getRemoteUrl())
                            .transform(new CenterCrop())
                            .into((ImageView) helper.getView(R.id.message_image_left_content));
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_image_left_img));
                }
                break;
            case 2001:
                helper.addOnClickListener(R.id.message_image_right_content);
                if (item.getEmMessage() == null) {
                    Glide.with(mContext).load(item.getFileUrl())
                            .transform(new CenterCrop())
                            .into((ImageView) helper.getView(R.id.message_image_right_content));
                    Glide.with(mContext)
                            .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_head : item.getSelfAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_image_right_img));
                } else {
                    EMImageMessageBody imageMessageBody_right = (EMImageMessageBody) item.getEmMessage().getBody();
                    Glide.with(mContext).load(imageMessageBody_right.getRemoteUrl())
                            .transform(new CenterCrop())
                            .into((ImageView) helper.getView(R.id.message_image_right_content));
                    Glide.with(mContext)
                            .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_head : item.getSelfAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_image_right_img));
                }

                break;
//            case 30:
//                break;
//            case 31:
//                break;
//            case 40:
//                break;
//            case 41:
//                break;
            case 5000:
                helper.addOnClickListener(R.id.message_voice_left_content);
                if (item.getEmMessage() == null) {
                    String attach = item.getAttach();
                    int lengthTime = 0;
                    try {
                        JSONObject jsonObject = new JSONObject(attach);
                        if (jsonObject.has("length")) {
                            lengthTime = jsonObject.getInt("length");
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    helper.setText(R.id.message_voice_left_timelength, lengthTime + "\"");
                    MessageBackgroundLeft messageBackgroundLeft = helper.getView(R.id.message_voice_left_content);
                    ViewGroup.LayoutParams layoutParamsleft = messageBackgroundLeft.getLayoutParams();
                    if (lengthTime > 0) {
                        layoutParamsleft.width = lengthTime * 35 + 250;
                    }
                    if (layoutParamsleft.width >= 600) {
                        layoutParamsleft.width = 600;
                    }
                    messageBackgroundLeft.setLayoutParams(layoutParamsleft);
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_voice_left_img));
//                    Glide.with(mContext).load(R.drawable.voice_left_playing).into((ImageView) helper.getView(R.id.message_voice_left_icon));
                } else {
                    //对方语音
                    EMVoiceMessageBody emVoiceMessageBody_left = (EMVoiceMessageBody) item.getEmMessage().getBody();
                    helper.setText(R.id.message_voice_left_timelength, emVoiceMessageBody_left.getLength() + "\"");
                    MessageBackgroundLeft messageBackgroundLeft = helper.getView(R.id.message_voice_left_content);
                    ViewGroup.LayoutParams layoutParamsleft = messageBackgroundLeft.getLayoutParams();
                    if (emVoiceMessageBody_left.getLength() > 0) {
                        layoutParamsleft.width = emVoiceMessageBody_left.getLength() * 35 + 250;
                    }
                    if (layoutParamsleft.width >= 600) {
                        layoutParamsleft.width = 600;
                    }
                    messageBackgroundLeft.setLayoutParams(layoutParamsleft);
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_voice_left_img));
//                    Glide.with(mContext).load(R.drawable.voice_left_playing3).into((ImageView) helper.getView(R.id.message_voice_left_icon));
                }
                break;
            case 5001:
                helper.addOnClickListener(R.id.message_voice_right_content);
                if (item.getEmMessage() == null) {
                    //自己语音
                    String attach = item.getAttach();
                    int lengthTime = 0;
                    try {
                        JSONObject jsonObject = new JSONObject(attach);
                        if (jsonObject.has("length")) {
                            lengthTime = jsonObject.getInt("length");
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    helper.setText(R.id.message_voice_right_timelength, lengthTime + "\"");
                    MessageBackgroundRight messageBackgroundright = helper.getView(R.id.message_voice_right_content);
                    ViewGroup.LayoutParams layoutParamsright = messageBackgroundright.getLayoutParams();
                    if (lengthTime > 0) {
                        layoutParamsright.width = lengthTime * 35 + 250;
                    }
                    if (layoutParamsright.width >= 600) {
                        layoutParamsright.width = 600;
                    }
                    messageBackgroundright.setLayoutParams(layoutParamsright);
                    Glide.with(mContext)
                            .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_voice_right_img));
//                    Glide.with(mContext).load(R.drawable.message_voice_right).into((ImageView) helper.getView(R.id.message_voice_right_icon));
                } else {
                    //自己语音
                    EMVoiceMessageBody emVoiceMessageBody_right = (EMVoiceMessageBody) item.getEmMessage().getBody();
                    helper.setText(R.id.message_voice_right_timelength, emVoiceMessageBody_right.getLength() + "\"");
                    MessageBackgroundRight messageBackgroundright = helper.getView(R.id.message_voice_right_content);
                    ViewGroup.LayoutParams layoutParamsright = messageBackgroundright.getLayoutParams();
                    if (emVoiceMessageBody_right.getLength() > 0) {
                        layoutParamsright.width = emVoiceMessageBody_right.getLength() * 35 + 250;
                    }
                    if (layoutParamsright.width >= 600) {
                        layoutParamsright.width = 600;
                    }
                    messageBackgroundright.setLayoutParams(layoutParamsright);
                    Glide.with(mContext)
                            .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_voice_right_img));
//                    Glide.with(mContext).load(R.drawable.message_voice_right).into((ImageView) helper.getView(R.id.message_voice_right_icon));
                }
                break;
            case 7001: {
                String patientName = "";
                String gender = "";
                String age = "";
                String type = "";
                String chiefComplaint = "";
                int chargeId = 0;
                String sendTime = "";
                if (item.getEmMessage() == null) {
                    String customExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(customExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("patientName")) {
                                patientName = jsonObject.getString("patientName");
                            } else if (jsonObject.has("gender")) {
                                gender = jsonObject.getString("gender");
                            } else if (jsonObject.has("age")) {
                                age = jsonObject.getString("age");
                            } else if (jsonObject.has("chiefComplaint")) {
                                chiefComplaint = jsonObject.getString("chiefComplaint");
                            } else if (jsonObject.has("type")) {
                                type = jsonObject.getString("type");
                            }
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    chargeId = item.getChargesListId();
                    sendTime = item.getSendTime();
                } else {
                    sendTime = DataUtils.long2string(item.getEmMessage().getMsgTime(), "yyyy-MM-dd HH:mm:ss");
                    EMCustomMessageBody body1 = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params1 = body1.getParams();
                    ALog.i("convert", "convert: " + params1);
                    patientName = params1.get("patientName");
                    gender = params1.get("gender");
                    age = params1.get("age");
                    type = params1.get("type");
                    chiefComplaint = params1.get("chiefComplaint");
                    chargeId = Integer.parseInt(params1.get("chargesListId"));
////                温馨提示：<text>医生均在临床一线工作，还请耐心等待，医生接诊后会第一时间通知您。

                }
                if (isInquiryRecord) {
                    helper.setVisible(R.id.message_description_right_detail, false);
//                        helper.setVisible(R.id.message_description_right_hint, false);
                    helper.setVisible(R.id.doctor_helper, false);
                } else {
                    helper.setVisible(R.id.message_description_right_detail, true);
//                        helper.setVisible(R.id.message_description_right_hint, true);
                    helper.setVisible(R.id.doctor_helper, true);

                }
                //自己发送问诊单
                Glide.with(mContext)
                        .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_description_right_img));
                helper.setText(R.id.message_description_right_patientinfo, patientName + "\t\t" + gender + "\t\t" + age);
                helper.setText(R.id.message_description_right_chiefComplaint, chiefComplaint);
                if (item.getChatType() == EMMessage.ChatType.Chat) {
                    helper.setText(R.id.message_doctor_helper_left_content, "您的问诊信息已提交给医生。医生接诊后，会通过短信/微信公众号再次通知您，请留意医生接诊通知，及时查看医生回复。");
                    helper.setVisible(R.id.message_doctor_helper_left_name, true);
                    helper.setText(R.id.message_time, sendTime);
                    helper.setText(R.id.message_description_right_hint, "温馨提示：医生均在临床一线工作，还请耐心等待，医生接诊后会第一时间通知您。");
                    if (type.equals("4")) {
                        helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg2);
                        helper.setText(R.id.message_description_right_title, "电话问诊");
                        helper.setText(R.id.message_description_right_title_time, "(通话15分钟内)");
                        helper.setText(R.id.message_description_right_time_detail, relevantDateStr + startTime_description + "-" + endTime_description);
                        helper.setVisible(R.id.message_description_right_time, true);
                        helper.setText(R.id.message_description_right_hint, "温馨提示:医生将于" + relevantDateStr + startTime_description + "至" + endTime_description + "按照候诊顺序依次接诊，请您耐心等待~");
                    } else if (type.equals("2") || type.equals("3")) {
                        helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg1);
                        helper.setText(R.id.message_description_right_title, "预约图文问诊");
                        helper.setText(R.id.message_description_right_time_detail, relevantDateStr + startTime_description + "-" + endTime_description);
                        helper.setVisible(R.id.message_description_right_time, true);
                        helper.setText(R.id.message_description_right_title_time, "(15分钟)");
                    } else if (type.equals("0")) {
                        helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg);
                        helper.setVisible(R.id.message_description_right_time, false);
                        helper.setText(R.id.message_description_right_title, "图文问诊");
                        helper.setText(R.id.message_description_right_title_time, "(24小时)");
                    } else if (type.equals("7")) {
                        helper.setVisible(R.id.message_description_right_time, false);
                        helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg3);
                        helper.setText(R.id.message_description_right_title_time, "(通话15分钟内)");
                        helper.setText(R.id.message_description_right_title, "视频问诊");
                        helper.setText(R.id.message_description_right_hint, "温馨提示:视频问诊仅支持医生发起，建议您先与医生文字交流，告知医生您方便接听视频的时间，待医生查看消息后，即可向您发起视频。");
                    } else if (type.equals("8")) {
                        helper.setVisible(R.id.doctor_helper_text_left, false);
                        helper.setVisible(R.id.message_description_right_time, false);
                        helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg);
                        helper.setText(R.id.message_description_right_title_time, "");
                        helper.setText(R.id.message_description_right_title, "诊后免费限次咨询");
                    }
                    helper.setVisible(R.id.doctor_helper, true);
                    helper.setVisible(R.id.message_description_right_hint, true);
                    helper.setVisible(R.id.message_description_right_title_time, true);
                } else {
                    if (ProjectConfigure.Open.isOpenGroup) {
                        if (type.equals("1")) {
                            helper.setVisible(R.id.message_description_right_time, false);
                            helper.setVisible(R.id.message_description_right_hint, false);
                            helper.setVisible(R.id.message_description_right_title_time, false);
                            helper.setText(R.id.message_description_right_title, "复诊开方");
                            helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg);
                            Glide.with(mContext).load(item.getSelfAvator()).transform(new CenterCrop(), new CircleCrop()).into((ImageView) helper.getView(R.id.message_description_right_img));
                            helper.setText(R.id.message_doctor_helper_left_content, "请问您需要咨询什么问题？");
                            helper.setText(R.id.message_time, sendTime);
                            helper.setVisible(R.id.message_doctor_helper_left_name, false);
                        } else if (type.equals("9")) {
                            helper.setVisible(R.id.message_description_right_time, false);
                            helper.setVisible(R.id.message_description_right_hint, false);
                            helper.setVisible(R.id.message_description_right_title_time, false);
                            helper.setText(R.id.message_description_right_title, "复诊开方");
                            helper.setBackgroundRes(R.id.rl_check_detail, R.drawable.message_description_head_bg);
                           Glide.with(mContext).load(item.getSelfAvator()).transform(new CenterCrop(), new CircleCrop()).into((ImageView) helper.getView(R.id.message_description_right_img));
                            helper.setText(R.id.message_doctor_helper_left_content, "请问您需要咨询什么问题？");
                            helper.setText(R.id.message_time, sendTime);
                            helper.setVisible(R.id.message_doctor_helper_left_name, false);
                        }
                    }
                }
                int finalChargeId = chargeId;
                if (chargeEntity != null && chargeEntity.getCharge_status().equals("waiting")) {
                    ClickUtils.setFastOnClickListener(helper.getView(R.id.message_description_right_detail), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Bundle bundle = new Bundle();
                            bundle.putInt("chargeId", finalChargeId);
                            MessageUtils.push(mContext,
                                    KitArouterConstants.IM_DOCTORBUNDLE,
                                    KitArouterConstants.Message.ChargesSingleUpdate,
                                    bundle);
                        }
                    });
                } else {
                    ClickUtils.setFastOnClickListener(helper.getView(R.id.message_description_right_detail), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Bundle bundle = new Bundle();
                            bundle.putInt("chargeId", finalChargeId);
                            MessageUtils.push(mContext,
                                    KitArouterConstants.IM_DOCTORBUNDLE,
                                    KitArouterConstants.Message.ChargeSingle,
                                    bundle);
                        }
                    });
                }

            }
            break;
            case 7002: {
                //                //温馨提示：问诊过程中，医生可能因手术或出诊暂时离开，您可以继续回复，医生会抽空为您解答，请多一点耐心哟。
                String type = "";
                String dataTime = "";
                String patientEndTimeShow = "";
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_time, item.getSendTime());
                    String customExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(customExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("type")) {
                                type = jsonObject.getString("type");
                            }
                            if (jsonObject.has("relevantDate")) {
                                dataTime = jsonObject.getString("relevantDate");
                            }
                            if (jsonObject.has("patientEndTimeShow")) {
                                patientEndTimeShow = jsonObject.getString("patientEndTimeShow");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    helper.setText(R.id.message_time, DataUtils.long2string(item.getEmMessage().getMsgTime(), "yyyy-MM-ss HH:mm:ss"));
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params1 = body.getParams();
                    if (params1.containsKey("type")){
                        type = params1.get("type");
                    }
                    if (params1.containsKey("relevantDate")){
                        dataTime = params1.get("relevantDate");
                    }
                    if (params1.containsKey("patientEndTimeShow")){
                        patientEndTimeShow = params1.get("patientEndTimeShow");
                    }
                }
                helper.setVisible(R.id.message_received_hint_center, true);
                if (type.equals("4")) {
                    helper.setText(R.id.message_received_hint_center,
                            "温馨提示:医生已接诊，您可以在对话框中补充病历信息，请保持手机畅通，注意接听" + callPhone + "来电。");
//                } else if (type.equals("0") || type.equals("2")) {
                } else if (type.equals("0")) {
                    helper.setText(R.id.message_received_hint_center, "温馨提示：问诊过程中，医生可能因手术或出诊暂时离开，您可以继续回复，医生会抽空为您解答，请多一点耐心哟。");
                } else if (type.equals("7")) {
                    String a = "\n\n温馨提示:医生已接诊，预计会在" + dataTime + "与您进行视频通话，请注意接听！您可以继续补充病情信息！";
                    helper.setText(R.id.message_received_hint_center, "温馨提示：问诊过程中，医生可能因手术或出诊暂时离开，您可以继续回复，医生会抽空为您解答，请多一点耐心哟。" + a);
                }  else if (type.equals("3")) {
                    helper.setVisible(R.id.message_received,false);
                    String a = "温馨提示：问诊已开始。本次问诊为预约图文问诊，预计于"+patientEndTimeShow+"结束，请尽快与医生完成沟通。";
//                    helper.setText(R.id.message_received_hint_center, "温馨提示：问诊过程中，医生可能因手术或出诊暂时离开，您可以继续回复，医生会抽空为您解答，请多一点耐心哟。"+a);
                    helper.setText(R.id.message_received_hint_center, a);
                } else if (type.equals("8")) {
                    helper.setText(R.id.message_received, "咨询已开始，请及时与医生沟通");
                } else {
                    helper.setVisible(R.id.message_received_hint_center, false);
                }

                if (item.getChatType() == EMMessage.ChatType.Chat) {
                    helper.setVisible(R.id.message_time_ll, true);
                } else {
                    helper.setVisible(R.id.message_time_ll, false);
                }


            }
            break;
            case 7003:
                Glide.with(mContext)
                        .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_presctiption_left_img));
                String prescriptionTime = "";
                String preliminary = "";
                String name = "";
                String norms = "";
                String amount = "";
                String prescriptionId = "";
                String title = "慧医天下用药建议";
                if (item.getEmMessage() == null) {
                    String customExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(customExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("prescriptionTime")) {
                                prescriptionTime = jsonObject.getString("prescriptionTime");
                            } else if (jsonObject.has("preliminary")) {
                                preliminary = jsonObject.getString("preliminary");
                            } else if (jsonObject.has("prescriptionId")) {
                                prescriptionId = jsonObject.getString("prescriptionId");
                            } else if (jsonObject.has("webHospitalName")) {
                                title = jsonObject.getString("webHospitalName");
//                               if ("cd".equals(webHospitalCode)){
//                                   title = "成都慧医天下互联网医院用药建议";
//
//                               }else if ("hn".equals(webHospitalCode)){
//                                   title = "海南医理互联网医院用药建议";
//
//                               }else{
//                                   title = "慧医天下用药建议";
//                               }
                            } else if (jsonObject.has("drugs")) {
                                String drugs1 = jsonObject.getString("drugs");
                                JSONArray drugss = new JSONArray(drugs1);
//                                JSONArray drugss = jsonObject.getJSONArray("drugs");
                                JSONObject drugs = drugss.getJSONObject(0);
                                if (drugs.has("name")) {
                                    name = drugs.getString("name");
                                }
                                if (drugs.has("amount")) {
                                    amount = drugs.getString("amount");
                                }
                                if (drugs.has("norms")) {
                                    norms = drugs.getString("norms");
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    helper.setText(R.id.message_presctiption_left_diagnose, preliminary);
                    helper.setText(R.id.message_presctiption_left_rp, name);
                    helper.setText(R.id.message_presctiption_left_norms, norms + "\tx" + amount);
                    helper.setText(R.id.message_presctiption_left_data, prescriptionTime);
                    helper.setText(R.id.message_prescription_center, "温馨提示：医生已开具处方，建议您用药前仔细阅读药品说明书，了解药品的不良反应、禁忌症和注意事项等。");
                } else {
                    Glide.with(mContext)
                            .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                            .transform(new CenterCrop(), new CircleCrop())
                            .into((ImageView) helper.getView(R.id.message_presctiption_left_img));

                    EMCustomMessageBody body808 = (EMCustomMessageBody) item.getEmMessage().getBody();
                    //问诊模板结束

                    Map<String, String> params808 = body808.getParams();
                    if (params808 != null) {
                        if (params808.containsKey("preliminary")) {
                            helper.setText(R.id.message_presctiption_left_diagnose, params808.get("preliminary"));
                        }
                        if (params808.containsKey("prescriptionId")) {
                            prescriptionId = params808.get("prescriptionId");
                        }
                        if (params808.containsKey("webHospitalName")) {
                            title = params808.get("webHospitalName");
//                            if ("cd".equals(webHospitalCode)){
//                                title = "成都慧医天下互联网医院用药建议";
//
//                            }else if ("hn".equals(webHospitalCode)){
//                                title = "海南医理互联网医院用药建议";
//
//                            }else{
//                                title = "慧医天下用药建议";
//                            }
                        }

                        if (params808.containsKey("drugs")) {
                            String drug = params808.get("drugs");
                            JSONObject jsonObject = null;
                            try {
                                JSONArray jsonArray = new JSONArray(drug);
                                jsonObject = jsonArray.getJSONObject(0);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            if (jsonObject != null) {
                                if (jsonObject.has("name")) {
                                    try {
                                        helper.setText(R.id.message_presctiption_left_rp, jsonObject.getString("name"));
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                                if (jsonObject.has("norms") && jsonObject.has("amount")) {
                                    try {
                                        helper.setText(R.id.message_presctiption_left_norms, jsonObject.getString("norms") + "x" + jsonObject.getString("amount"));
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }

                        }
                        if (params808.containsKey("prescriptionTime")) {
                            helper.setText(R.id.message_presctiption_left_data, params808.get("prescriptionTime"));
                        }
                    }
                    helper.setText(R.id.message_prescription_center, "温馨提示：医生已开具处方，建议您用药前仔细阅读药品说明书，了解药品的不良反应、禁忌症和注意事项等。");

                }

                helper.setText(R.id.message_prescription_title, title);
                RequestParams jsonObject1 = new RequestParams();
                jsonObject1.put("prescriptionId", prescriptionId);
                HttpUtils.get("/ihospital-patient/ipatient/prescription/queryShowButton", jsonObject1, new HttpCallBack<ChatGroupPrescriptionStatusBean>() {
                    @Override
                    public void onSuccess(ChatGroupPrescriptionStatusBean chatGroupPrescriptionStatusBean, int i) {
                        if (chatGroupPrescriptionStatusBean.isResult()) {
                            chatprescriptiondata = chatGroupPrescriptionStatusBean.getData();
                            if (isInquiryRecord) {
                                helper.setVisible(R.id.message_presctiption_left_bt, false);
                            } else {
                                setPrescriptionStatus(helper, chatprescriptiondata,item.getChatType() == EMMessage.ChatType.ChatRoom);
                            }
                        }
                    }

                    @Override
                    public void onFailure(String s, int i) {
                    }
                });

                String finalPrescriptionId = prescriptionId;
                ClickUtils.setFastOnClickListener(helper.getView(R.id.message_prescription_card), new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        RequestParams params = new RequestParams();
                        params.put("prescriptionId", finalPrescriptionId);
                        HttpUtils.get(AllStringConstants.MessageUrl.checkPrescriptionEffective, params, new HttpCallBack<String>() {
                            @Override
                            public void onSuccess(String s, int i) {
                                if (chatprescriptiondata == null){
                                    ALog.e("chatprescriptiondata is null");
                                }else{
                                    if (chatprescriptiondata.getButtonShow() == 0){
                                        //超过72小时处方失效不展示按钮-展示失效
                                        ToastUtils.make().setBgColor(mContext.getResources().getColor(R.color.color_99000000))
                                                .setTextColor(mContext.getResources().getColor(R.color.white))
                                                .show(R.string.prescription_hint_passed);
                                    }else if (chatprescriptiondata.getButtonShow() == 1){
                                        //去预定
                                        if (chatprescriptiondata!=null){
                                            toNotOrder();
                                        }else{
                                            //chatprescriptiondata is null
                                            ALog.e("chatprescriptiondata is null");
                                        }
                                    }else if (chatprescriptiondata.getButtonShow() == 2){
                                        //去支付
                                        if (chatprescriptiondata!=null){
                                            toUnpaid();
                                        }else{
                                            //chatprescriptiondata is null
                                            ALog.e("chatprescriptiondata is null");
                                        }
                                    }else if (chatprescriptiondata.getButtonShow() == 3){
                                        //查看订单
                                        if (chatprescriptiondata!=null){
                                            Bundle bundle = new Bundle();
                                            bundle.putString("ordonnanceId", chatprescriptiondata.getPrescriptionId()+"");
                                            bundle.putString("dispatch", "2");
                                            bundle.putString("payChartFlag", "prescribeDrug");
                                            MessageUtils.push(mContext,
                                                    KitArouterConstants.IM_DOCTORBUNDLE,
                                                    KitArouterConstants.Message.Prescribe,
                                                    bundle);
                                        }else{
                                            //chatprescriptiondata is null
                                            ALog.e("chatprescriptiondata is null");
                                        }
                                    }else if (chatprescriptiondata.getButtonShow() == 4){
                                        //未下单处方审核不通打回医生修改
                                        ToastUtils.make().setBgColor(mContext.getResources().getColor(R.color.color_99000000))
                                                .setTextColor(mContext.getResources().getColor(R.color.white))
                                                .show(R.string.prescription_hint_edit);
                                    }else if (chatprescriptiondata.getButtonShow() == 5){
                                        //药师审核不通/医生复核不通过-展示未生效
                                        ToastUtils.make().setBgColor(mContext.getResources().getColor(R.color.color_99000000))
                                                .setTextColor(mContext.getResources().getColor(R.color.white))
                                                .show(R.string.prescription_hint_edit);
                                    }else if (chatprescriptiondata.getButtonShow() == 6){
                                        //医生撤回处方
                                        ToastUtils.make().setBgColor(mContext.getResources().getColor(R.color.color_99000000))
                                                .setTextColor(mContext.getResources().getColor(R.color.white))
                                                .show(R.string.prescription_hint_recall);
                                    }
                                }
                            }

                            @Override
                            public void onFailure(String s, int i) {
                                BaseBean baseBean = new Gson().fromJson(s, BaseBean.class);
                                if (!TextUtils.isEmpty(baseBean.getMsg())) {
                                    ToastUtils.make().setBgColor(mContext.getResources().getColor(R.color.color_99000000))
                                            .setTextColor(mContext.getResources().getColor(R.color.white))
                                            .show(baseBean.getMsg());
                                } else {
                                    ToastUtils.make().setBgColor(mContext.getResources().getColor(R.color.color_99000000))
                                            .setTextColor(mContext.getResources().getColor(R.color.white))
                                            .show("问诊已退诊，处方无法查看或预定");
                                }
                            }
                        });

                    }
                });


                break;
            case 7004:
                Glide.with(mContext)
                        .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_finish_img));
                String finishContent = null;
                String medicalRecordId = "";
                String chargesListId = "";
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_time, item.getSendTime());
                    String customExt = item.getCustomExt();
                    JSONArray jsonArray = null;
                    try {
                        jsonArray = new JSONArray(customExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("summary")) {
                                finishContent = jsonObject.getString("summary");
                            }
                            if (jsonObject.has("medicalRecordId")) {
                                medicalRecordId = jsonObject.getString("medicalRecordId");
                            }
                            if (jsonObject.has("chargesListId")) {
                                chargesListId = jsonObject.getString("chargesListId");
                            }
                            if (jsonObject.has("type")) {
                                if (jsonObject.getString("type").equals("8")) {
                                    helper.setText(R.id.message_received, "咨询已结束，如有疑问可再次咨询。");
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                } else {
                    helper.setText(R.id.message_time, DataUtils.long2string(item.getEmMessage().getMsgTime(), "yyyy-MM-ss HH:mm:ss"));
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("summary")) {
                        finishContent = params.get("summary");
                    }
                    if (params.containsKey("medicalRecordId")) {
                        medicalRecordId = params.get("medicalRecordId");
                    }
                    if (params.containsKey("chargesListId")) {
                        chargesListId = params.get("chargesListId");
                    }

                    if (params.containsKey("type")) {
                        if (params.get("type").equals("8")) {
                            helper.setText(R.id.message_received, "咨询已结束，如有疑问可再次咨询。");
                        }
                    }

                }

                if (finishContent != null) {
                    helper.setVisible(R.id.message_finish, true);
                    helper.setText(R.id.message_finish_content, finishContent);
                    String finalMedicalRecordId = medicalRecordId;
                    String finalchargesListId = chargesListId;
                    if (isInquiryRecord) {
                        helper.setVisible(R.id.message_finish_bt, false);
                    } else {
                        helper.setVisible(R.id.message_finish_bt, true);
                    }
                    ClickUtils.setFastOnClickListener(helper.getView(R.id.message_finish_bt), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
//                            Bundle bundle = new Bundle();
//                            bundle.putInt("chargesListId", Integer.valueOf(finalMedicalRecordId).intValue());
//                            bundle.putInt("type", 1);
//                            bundle.putString("doctorImageUrl", item.getFromAvator() == null || item.getFromAvator() == "" ? "" : item.getFromAvator());
//                            MessageUtils.push(mContext, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.TreatmentSuggestion, bundle);
                            Bundle bundle = new Bundle();
//                            bundle.putInt("chargesListId", Integer.valueOf(finalMedicalRecordId).intValue());
                            bundle.putInt("chargesListId", Integer.valueOf(finalchargesListId).intValue());
//                            bundle.putInt("type", 1);
//                            bundle.putString("doctorImageUrl", item.getFromAvator() == null || item.getFromAvator() == "" ? "" : item.getFromAvator());
                            MessageUtils.push(mContext, KitArouterConstants.IM_DOCTORBUNDLE, KitArouterConstants.Mine.Records, bundle);
                        }
                    });
                } else {
                    helper.setVisible(R.id.message_finish, false);

                }

                break;
            case 7005:
//                if (item.getEmMessage() == null) {
//                    helper.setText(R.id.message_time, item.getSendTime());
//                } else {
//                    try {
//                        helper.setText(R.id.message_time, DataUtils.longToString(item.getEmMessage().getMsgTime(), "yyyy-MM-ss HH:mm:ss"));
//                    } catch (ParseException e) {
//                        e.printStackTrace();
//                    }
//                }
                Glide.with(mContext)
                        .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_evaluate_left_img));
                ALog.i(TAG, "convert: " + item.getChargesListId());
                ALog.i(TAG, "convert: " + chargesIds);
                if (chargesIds.contains(item.getChargesListId())) {
                    helper.setVisible(R.id.message_evaluate_left_bt, false);
                } else {
                    helper.setVisible(R.id.message_evaluate_left_bt, true);
                }

                if (isInquiryRecord) {
                    helper.setVisible(R.id.message_evaluate_left_bt, false);
                }

                ClickUtils.setFastOnClickListener(helper.getView(R.id.message_evaluate_left_bt), new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        clickMessageEvaluate(item);
                    }
                });

                break;
            case 7006:
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_time, item.getSendTime());
                } else {
                    helper.setText(R.id.message_time, DataUtils.long2string(item.getEmMessage().getMsgTime(), "yyyy-MM-ss HH:mm:ss"));

                }
                helper.setText(R.id.message_stoptemplate_content, "温馨提示：问诊模板结束");

                break;
            case 7007:
                String content = "";
                if (item.getEmMessage() == null) {
                    String customExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(customExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("content")) {
                                content = jsonObject.getString("content");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody customMessageBody7007 = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = customMessageBody7007.getParams();
                    if (params.containsKey("content")) {
                        content = params.get("content");
                    }
                }
                helper.setText(R.id.message_doctor_helper_left_content, content);
                helper.setVisible(R.id.message_doctor_helper_left_name, true);
                break;
            case 7008:
                int commentScore = 1;
                String commentScoreName = "很不满意";
                String rewardSkuId = "";
                if (item.getEmMessage() == null) {
                    String customExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(customExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("commentScore")) {
                                commentScore = jsonObject.getInt("commentScore");
                            }
                            if (jsonObject.has("commentScoreName")) {
                                commentScoreName = jsonObject.getString("commentScoreName");
                            }
                            if (jsonObject.has("rewardSkuId")) {
                                rewardSkuId = jsonObject.getString("rewardSkuId");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        JSONObject jsonObject = null;
                        try {
                            jsonObject = new JSONObject(customExt);
                            if (jsonObject != null) {
                                if (jsonObject.has("commentScore")) {
                                    commentScore = jsonObject.getInt("commentScore");
                                }
                                if (jsonObject.has("commentScoreName")) {
                                    commentScoreName = jsonObject.getString("commentScoreName");
                                }
                                if (jsonObject.has("rewardSkuId")) {
                                    rewardSkuId = jsonObject.getString("rewardSkuId");
                                }
                            }
                        } catch (JSONException jsonException) {
                            jsonException.printStackTrace();
                        }
                    }

                } else {
                    EMCustomMessageBody customMessageBody7008 = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = customMessageBody7008.getParams();
                    if (params.containsKey("commentScore")) {
                        commentScore = Integer.valueOf(params.get("commentScore")).intValue();
                    }
                    if (params.containsKey("commentScoreName")) {
                        commentScoreName = params.get("commentScoreName");
                    }
                    if (params.containsKey("rewardSkuId")) {
                        rewardSkuId = params.get("rewardSkuId");
                    }
                }
                RatingBar ratingBar = helper.getView(R.id.message_patient_evaluate_finish_stars);
                ratingBar.setRating(commentScore);
                helper.setText(R.id.message_patient_evaluate_finish_content, commentScoreName);
            {
                if (!TextUtils.isEmpty(rewardSkuId) && !rewardSkuId.equals("null")) {
                    RequestParams jsonObject = new RequestParams();
                    jsonObject.put("giftId", rewardSkuId);
                    HttpUtils.get("/apivbp/api/gift/get", jsonObject, new HttpCallBack<GiftEntity>() {
                        @Override
                        public void onSuccess(GiftEntity giftEntity, int i) {
                            if ("200".equals(giftEntity.getStatus()) && giftEntity.getData() != null) {
                                Glide.with(mContext)
                                        .load(giftEntity.getData().getImageUrl())
                                        .transform(new CenterCrop())
                                        .into((ImageView) helper.getView(R.id.message_patient_evaluate_finish_gift));
                                helper.setVisible(R.id.message_patient_evaluate_finish_gift_ll, true);
                            }
                        }

                        @Override
                        public void onFailure(String s, int i) {
                        }
                    });
                }

            }
            Glide.with(mContext)
                    .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                    .transform(new CenterCrop(), new CircleCrop())
                    .into((ImageView) helper.getView(R.id.message_patient_evaluate_finish_img));
            if (isInquiryRecord) {
                helper.setVisible(R.id.message_patient_evaluate_finish_todetail, false);
            } else {
                helper.setVisible(R.id.message_patient_evaluate_finish_todetail, true);
            }

            ClickUtils.setFastOnClickListener(helper.getView(R.id.message_patient_evaluate_finish_todetail), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickMessageEvaluate(item);
                }
            });

            break;
            case 7009:
                helper.setText(R.id.message_text_left_content, "感谢您对我服务提出建议和评价。");
                Glide.with(mContext)
                        .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_text_left_img));
                break;
            case 7010: {
                String settingTime = "";
                if (item.getEmMessage() == null) {
                    String mCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(mCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("settingTime")) {
                                settingTime = jsonObject.getString("settingTime");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("settingTime")) {
                        settingTime = params.get("settingTime");
                    }
                }
                if (TextUtils.isEmpty(settingTime)) {
                    ALog.e("settingTime is empty");
                    helper.setText(R.id.message_hint_center, "温馨提示：医生将于null与您通话。为保护您和医生的号码隐私，届时平台将以021或023开头的电话依次拨通医生和您的电话。请注意接听！");
                } else {
                    long l = Long.parseLong(settingTime);
                    String s = DataUtils.long2string(l, DataUtils.Type1);
                    String time = DataUtils.long2string(l, DataUtils.Type4);
                    String now_month_day = DataUtils.long2string(l, DataUtils.Type6);
                    helper.setText(R.id.message_hint_center, "温馨提示：医生将于" + s + "与您通话。为保护您和医生的号码隐私，届时平台将以021或023开头的电话依次拨通医生和您的电话。请注意接听！");
                }
            }
            break;
//            case 8071:
//                //问诊模板结束
//                helper.setText(R.id.message_stoptemplate_content, "温馨提示：问诊模板结束");
//                break;
//            case 8080:
//            case 8081:
//                //医生发送问诊单
//                Glide.with(mContext)
//                        .load(item.getFromAvator()==null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
//                        .transform(new CenterCrop(), new CircleCrop())
//                        .into((ImageView) helper.getView(R.id.message_presctiption_left_img));
//
//
//                EMCustomMessageBody body808 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                //问诊模板结束
//
//                Map<String, String> params808 = body808.getParams();
//                if (params808!=null){
//                    if (params808.containsKey("preliminary")){
//                        helper.setText(R.id.message_presctiption_left_diagnose,params808.get("preliminary"));
//                    }
//                    if (params808.containsKey("drugs")){
//                        String drug = params808.get("drugs");
//                        JSONObject jsonObject = null;
//                        try {
//                            JSONArray jsonArray = new JSONArray(drug);
//                            jsonObject = jsonArray.getJSONObject(0);
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                       if (jsonObject !=null){
//                           if (jsonObject.has("name")){
//                               try {
//                                   helper.setText(R.id.message_presctiption_left_rp,jsonObject.getString("name"));
//                               } catch (JSONException e) {
//                                   e.printStackTrace();
//                               }
//                           }
//                           if (jsonObject.has("norms")&& jsonObject.has("amount")){
//                               try {
//                                   helper.setText(R.id.message_presctiption_left_norms,jsonObject.getString("norms")+"x"+jsonObject.getString("amount"));
//                               } catch (JSONException e) {
//                                   e.printStackTrace();
//                               }
//                           }
//                       }
//
//                    }
//                    if (params808.containsKey("prescriptionTime")){
//                        helper.setText(R.id.message_presctiption_left_data,params808.get("prescriptionTime"));
//                    }
//                }
//                helper.setText(R.id.message_prescription_center, "温馨提示：医生已开具处方，药师正在审核中，审核通过后，您可以根据提示在线购买药品。");
//                break;
//            case 9010:
//                //温馨提示：医生为您延长{{item.customExts.duration}}分钟问诊时间，您可以继续向医生进行提问。
//                EMCustomMessageBody customMessageBody = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String duration = customMessageBody.getParams().get("duration");
//                helper.setText(R.id.message_hint_center,duration);
//                break;
//            case 9020:
//            case 9021:
//                //温馨提示：医生已开具处方，药师正在审核中，审核通过后，您可以根据提示在线购买药品。
//                helper.setText(R.id.message_hint_center,"");
//                break;
//
//            case 9040:
////                温馨提示：{{item.customExt&&item.customExts.content}}
//                EMCustomMessageBody customMessageBody4 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content4 = customMessageBody4.getParams().get("content");
//                helper.setText(R.id.message_hint_center,content4);
//                break;
//            case 9060:
////            {{item.customExts.content}}
//                EMCustomMessageBody customMessageBody6 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content6 = customMessageBody6.getParams().get("content");
//                helper.setText(R.id.message_hint_center,content6);
//                break;
//            case 9070:
////                温馨提示：{{item.customExts.failReason || item.customExts.failReason}}
//                EMCustomMessageBody customMessageBody7 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content7 = customMessageBody7.getParams().get("failReason");
//                helper.setText(R.id.message_hint_center,content7);
//                break;
//            case 9080:
//                EMCustomMessageBody customMessageBody80 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content80 = customMessageBody80.getParams().get("content");
//                helper.setText(R.id.message_hint_center,content80);
//                break;
//            case 9081:
//                EMCustomMessageBody customMessageBody81 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content81 = customMessageBody81.getParams().get("content");
//                helper.setText(R.id.message_hint_center,content81);
//                break;
//            case 9090:
//            case 9091:
//                EMCustomMessageBody customMessageBody9 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content9 = customMessageBody9.getParams().get("content");
//                helper.setText(R.id.message_hint_center,content9);
//                break;
//            case 9130:
//            case 9131:
//                EMCustomMessageBody customMessageBody13 = (EMCustomMessageBody) item.getEmMessage().getBody();
//                String content13 = customMessageBody13.getParams().get("content");
//                helper.setText(R.id.message_hint_center,content13);
//                break;
            case 7011:
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_time, item.getSendTime());
                } else {
                    helper.setText(R.id.message_time, DataUtils.long2string(item.getEmMessage().getMsgTime(), DataUtils.Type1));
                }
                break;
            case 7012:
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_time, item.getSendTime());
                } else {
                    helper.setText(R.id.message_time, DataUtils.long2string(item.getEmMessage().getMsgTime(), DataUtils.Type1));
                }
//                helper.setText(R.id.message_hint_center, sfContent);
                helper.setText(R.id.message_hint_center, "医生总共最多回复3条消息，有效期24小时，到期结束，请把咨询问题尽量描述清楚，方便医生作答");
                break;
            case 7013: {
                String settingTime = "";
                if (item.getEmMessage() == null) {
                    String mCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(mCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("settingTime")) {
                                settingTime = jsonObject.getString("settingTime");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("settingTime")) {
                        settingTime = params.get("settingTime");
                    }
                }
                if (TextUtils.isEmpty(settingTime)) {
                    ALog.e("settingTime is empty");
                    helper.setText(R.id.message_hint_center, "温馨提示：医生因故取消null的通话计划，建议您耐心等待医生回复或先以文字与医生进行沟通。");
                } else {
                    long l = Long.parseLong(settingTime);
                    String s = DataUtils.long2string(l, DataUtils.Type1);
                    helper.setText(R.id.message_hint_center, "温馨提示：医生因故取消" + s + "的通话计划，建议您耐心等待医生回复或先以文字与医生进行沟通。");
                }
            }
            break;
            case 7014: {
                String updateSettingTime = "";
                if (item.getEmMessage() == null) {
                    String updateCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(updateCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("settingTime")) {
                                updateSettingTime = jsonObject.getString("settingTime");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("settingTime")) {
                        updateSettingTime = params.get("settingTime");
                    }
                }
                long l = Long.parseLong(updateSettingTime);
                String time = DataUtils.long2string(l, DataUtils.Type4);
                String now_month_day = DataUtils.long2string(l, DataUtils.Type6);
                helper.setText(R.id.message_hint_center, "温馨提示：您的接诊医生因故修改了电话问诊通话时间，将于" + now_month_day + " " + time + "拨打您的电话，届时您会收到（0571或028）开头的来电，请您留意接听。");
            }
            break;
            case 7015: {
                String missedCaller = "";
                String appointmentTime = "";
                String mobile = "";
                if (item.getEmMessage() == null) {
                    String mCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(mCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("missedCaller")) {
                                missedCaller = jsonObject.getString("missedCaller");
                            }
                            if (jsonObject.has("appointmentTime")) {
                                appointmentTime = jsonObject.getString("appointmentTime");
                            }
                            if (jsonObject.has("mobile")) {
                                mobile = jsonObject.getString("mobile");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("missedCaller")) {
                        missedCaller = params.get("missedCaller");
                    }
                    if (params.containsKey("appointmentTime")) {
                        appointmentTime = params.get("appointmentTime");
                    }
                    if (params.containsKey("mobile")) {
                        mobile = params.get("mobile");
                    }
                }
                if (TextUtils.isEmpty(missedCaller) || TextUtils.isEmpty(appointmentTime) || TextUtils.isEmpty(mobile)) {
                    ALog.e("middsedCaller/appointmentTime/mobile is empty");
                    helper.setText(R.id.message_miss_phone_hint, "null在忙，无法按照约定时间与您通话，您可以与医生在线沟通后重新预约问诊时间或联系客服协调通话时间。");
                } else if (missedCaller.equals("doctor")) {
                    helper.setText(R.id.message_miss_phone_hint, "医生在忙，无法按照约定时间与您通话，您可以与医生在线沟通后重新预约问诊时间或联系客服协调通话时间。");
                    helper.setText(R.id.message_hint_center, "温馨提示：医生于" + appointmentTime + "拨打您的电话号码" + mobile + "未接通。建议您尽快与医生文字沟通，确认通话时间后，由医生重新拨打。");
                } else if (missedCaller.equals("patient")) {
                    helper.setText(R.id.message_miss_phone_hint, "患者在忙，无法按照约定时间与您通话，您可以与医生在线沟通后重新预约问诊时间或联系客服协调通话时间。");
                    helper.setText(R.id.message_hint_center, "温馨提示：患者于" + appointmentTime + "拨打您的电话号码" + mobile + "未接通。建议您尽快与医生文字沟通，确认通话时间后，由医生重新拨打。");
                }


            }


            ClickUtils.setFastOnClickListener(helper.getView(R.id.message_miss_phone_call_content), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PermissionManager.getInstance()
                            .get(mContext)
                            .requestPermissions(
                                    new String[]{Manifest.permission.CALL_PHONE}
                                    ,
                                    new String[]{"允许应用使用拨打电话权限"})
                            .requestCodes(0xa1)
                            .setmRequestPermissionCallBack(new PermissionManager.RequestPermissionCallBack() {
                                @Override
                                public void noM() {

                                }

                                @Override
                                public void granted() {
                                    MessageCallApi messageCallApi = (MessageCallApi) ARouter.getInstance().build(ARouterConstants.MessageModuleImpl).navigation();
                                    ArrayList<String> strings = new ArrayList<>();
                                    strings.add("4000867818");
                                    messageCallApi.openKefu(strings, mContext);
                                }

                                @Override
                                public void denied() {

                                }
                            })
                            .request();

                }
            });
            break;
            case 7016: {
                String duration = "";
                String callStartTime = "";
                if (item.getEmMessage() == null) {
                    String updateCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(updateCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("duration")) {
                                duration = jsonObject.getString("duration");
                            }
                            if (jsonObject.has("callStartTime")) {
                                callStartTime = jsonObject.getString("callStartTime");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("duration")) {
                        duration = params.get("duration");//9.08
                    }
                    if (params.containsKey("callStartTime")) {
                        callStartTime = params.get("callStartTime");//9.08
                    }
                }
                int time = 0;
                if (duration.contains(".")) {
                    time = (int) Double.parseDouble(duration);
                } else {
                    time = Integer.valueOf(time).intValue();
                }

//                int i = Integer.valueOf(duration.split(".")[0]).intValue();
//                helper.setText(R.id.message_phone_call_end, "温馨提示：您已于医生完成通话，通话时长：" + timeToHms(time, true));
                helper.setText(R.id.message_phone_call_end_hint, "温馨提示：您好，医生于" + callStartTime + "与您进行通话，通话时长：" + timeToHms(time, true) + "。 若您还有疑问，可在问诊结束前与医生进行沟通。");
            }
            break;
            case 7017:
                String message_refund_sign = "";
                if (item.getEmMessage() == null) {
                    String updateCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(updateCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("content")) {
                                message_refund_sign = jsonObject.getString("content");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("content")) {
                        message_refund_sign = params.get("content");
                    }
                }
//                helper.setText(R.id.message_refund_hint_center, "温馨提示：" + message_refund_sign);
                break;
            case 7018:
                //温馨提示：医生为您延长{{item.customExts.duration}}分钟问诊时间，您可以继续向医生进行提问。
                String duration = "";
                if (item.getEmMessage() == null) {
                    String updateCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(updateCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("duration")) {
                                duration = jsonObject.getString("duration");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("duration")) {
                        duration = params.get("duration");
                    }
                }
                helper.setText(R.id.message_delay_charges_center, "温馨提示：医生为您延长" + duration + "分钟问诊时间，您可以继续向医生进行提问。");
                break;
            case 7019: {
                String videoId = "";
                if (item.getEmMessage() == null) {
                    String updateCustomExt = item.getCustomExt();
                    try {
                        JSONArray jsonArray = new JSONArray(updateCustomExt);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("videoId")) {
                                videoId = jsonObject.getString("videoId");
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("videoId")) {
                        videoId = params.get("videoId");
                    }
                }
                if (!TextUtils.isEmpty(videoId)) {
                    RequestParams params = new RequestParams();
                    params.put("videoId", videoId);
                    HttpUtils.get(AllStringConstants.MessageUrl.queryVideoStatus, params, new HttpCallBack<VideoStatusBean>() {
                        @Override
                        public void onSuccess(VideoStatusBean s, int i) {
                            if (s.isResult() && (s.getData() == 1 || s.getData() == 4)){
                                helper.getView(R.id.message_start_video_fast).setEnabled(true);
                                helper.setText(R.id.message_start_video_fast,"立即通话");
                                helper.setBackgroundColor(R.id.message_start_video_fast,mContext.getResources().getColor(R.color.new_theme));
                            }else{
                                helper.getView(R.id.message_start_video_fast).setEnabled(false);
                                helper.setText(R.id.message_start_video_fast,"视频通话已结束");
                                helper.setBackgroundColor(R.id.message_start_video_fast,mContext.getResources().getColor(R.color.color_ccc));
                            }
                            //message_start_video_fast
                        }

                        @Override
                        public void onFailure(String s, int i) {
                            helper.getView(R.id.message_start_video_fast).setEnabled(false);
                            helper.setText(R.id.message_start_video_fast,"视频通话已结束");
                            helper.setBackgroundColor(R.id.message_start_video_fast,mContext.getResources().getColor(R.color.color_ccc));
                        }
                    });
                }


                ClickUtils.setFastOnClickListener(helper.getView(R.id.message_start_video_fast), new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        RequestParams jsonObject = new RequestParams();

                        if (item.getEmMessage() == null) {
                            jsonObject.put("chargesListId", item.getChargesListId());
                        } else {
                            EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                            Map<String, String> params = body.getParams();
                            if (params.containsKey("chargesListId")) {
                                jsonObject.put("chargesListId", params.get("chargesListId"));
                            }
                        }

                        HttpUtils.get("/ihospital-patient/ipatient/appointment/checkVideoStart", jsonObject, new HttpCallBack<CheckVideoStartEntity>() {
                            @Override
                            public void onSuccess(CheckVideoStartEntity entity, int i) {
                                if (entity != null && entity.isResult() && entity.getData() != null) {
                                    MessageCallApi messageCallApi = (MessageCallApi) ARouter.getInstance().build(ARouterConstants.MessageModuleImpl).navigation();
                                    messageCallApi.videoCall(entity.getData().getVideoNo());
                                } else {
                                    if (entity != null && !TextUtils.isEmpty(entity.getMsg())) {
                                        Toast.makeText(mContext, entity.getMsg(), Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }

                            @Override
                            public void onFailure(String s, int i) {

                            }
                        });
                    }
                });
            }
            break;
            case 7020:
                helper.setVisible(R.id.message_video_left_layout, false);
                Glide.with(mContext)
                        .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_video_left_img));
                helper.setText(R.id.message_video_left_timelength, "已取消");
                break;
            case 7021:
                helper.setVisible(R.id.message_video_right_layout, true);
                helper.setVisible(R.id.message_video_right_time, true);
                helper.setVisible(R.id.message_video_right_time1, true);
                Glide.with(mContext)
                        .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_video_right_img));
                if (item.getEmMessage() == null) {
                    helper.setText(R.id.message_time, item.getSendTime());
                } else {
                    helper.setText(R.id.message_time, DataUtils.long2string(item.getEmMessage().getMsgTime(), DataUtils.Type1));
                }
                helper.setText(R.id.message_video_right_timelength, "未接视频通话");
                helper.setText(R.id.message_video_right_sign, "温馨提示：医生向您发起视频通话未接通，您可以在问诊结束前与医生在线沟通后重新预约时间。");
                break;
            case 7022:
                helper.setVisible(R.id.message_video_right_layout, false);
                helper.setVisible(R.id.message_video_right_time, false);
                helper.setVisible(R.id.message_video_right_time1, false);
                Glide.with(mContext)
                        .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_video_right_img));
                helper.setText(R.id.message_video_right_timelength, "已拒绝");
                break;
            case 7023: {
                Glide.with(mContext)
                        .load(item.getSelfAvator() == null || item.getSelfAvator() == "" ? R.drawable.default_avator : item.getSelfAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_video_right_img));
                helper.setVisible(R.id.message_video_right_layout, true);
                helper.setVisible(R.id.message_video_right_time, false);
                helper.setVisible(R.id.message_video_right_time1, false);
                int l = 0;
                String startTime = "";
                if (item.getEmMessage() == null) {
                    try {
                        JSONArray jsonArray = new JSONArray(item.getCustomExt());
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("duration")) {
                                l = (int) jsonObject.getDouble("duration");
                            }
                            if (jsonObject.has("startTime")) {
                                startTime = jsonObject.getString("startTime");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("duration")) {
                        String s = params.get("duration");
                        if (!TextUtils.isEmpty(s)) {
                            double aDouble = Double.valueOf(s).doubleValue();
//                            String[] split = s.split(".");//6.41
                            if (aDouble > 0) {
                                l = (int) aDouble;
                            } else {
                                l = 0;
                            }
                        } else {
                            l = 0;
                        }

                    }
                    if (params.containsKey("startTime")){
                        startTime = params.get("startTime");
                    }
                }
//                helper.setText(R.id.message_video_right_sign, "温馨提示:您已与医生完成通话，通话时长:" + timeToHms(l, true) + "\n\n温馨提示：您好,医生已经跟您完成通话。若您还有疑问。可在对话框关闭前向医生提问");
                helper.setText(R.id.message_video_right_sign, "温馨提示：您好，医生于"+startTime+"与您进行视频，视频时长：" + timeToHms(l, true) + "。 若您还有疑问，可在问诊结束前与医生进行沟通。");
                helper.setText(R.id.message_video_right_timelength, "通话时长" + timeToHms(l, false));
            }
            break;
            case 7024: {
                Glide.with(mContext)
                        .load(item.getFromAvator() == null || item.getFromAvator() == "" ? R.drawable.default_avator : item.getFromAvator())
                        .transform(new CenterCrop(), new CircleCrop())
                        .into((ImageView) helper.getView(R.id.message_video_left_img));
                helper.setVisible(R.id.message_video_left_layout, true);
                int l = 0;
                String startTime = "";
                if (item.getEmMessage() == null) {
                    try {
                        JSONArray jsonArray = new JSONArray(item.getCustomExt());
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("duration")) {
                                l = (int) jsonObject.getDouble("duration");
                            }
                            if (jsonObject.has("startTime")) {
                                startTime = jsonObject.getString("startTime");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("duration")) {
                        String s = params.get("duration");
                        if (!TextUtils.isEmpty(s)) {
                            double aDouble = Double.valueOf(s).doubleValue();
                            if (aDouble > 0) {
                                l = (int) aDouble;
                            } else {
                                l = 0;
                            }
                        } else {
                            l = 0;
                        }

                    }
                    if (params.containsKey("startTime")){
                        startTime = params.get("startTime");
                    }
                }
                helper.setText(R.id.message_video_left_sign, "温馨提示：您好，医生于"+startTime+"与您进行视频，视频时长：" + timeToHms(l, true) + "。 若您还有疑问，可在问诊结束前与医生进行沟通。");
                helper.setText(R.id.message_video_left_timelength, "通话时长" + timeToHms(l, false));

            }
            break;
            case 7025: {
                ArrayList<MessageEtpConsultingDrugsEntity> messageEtpConsultingDrugsEntities = new ArrayList<>();
                if (item.getEmMessage() == null) {
                    try {
                        JSONArray jsonArray = new JSONArray(item.getCustomExt());
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("drugs")) {
                                String drugs = jsonObject.getString("drugs");
                                JSONArray jsonArray1 = new JSONArray(drugs);
                                for (int j = 0; j < jsonArray1.length(); j++) {
                                    JSONObject jsonObject2 = jsonArray1.getJSONObject(j);
                                    MessageEtpConsultingDrugsEntity messageEtpConsultingDrugsEntity = new MessageEtpConsultingDrugsEntity();
                                    if (jsonObject2.has("amount")) {
                                        messageEtpConsultingDrugsEntity.setAmount(jsonObject2.getInt("amount"));
                                    }
                                    if (jsonObject2.has("drugUnit")) {
                                        messageEtpConsultingDrugsEntity.setDrugUnit(jsonObject2.getString("drugUnit"));
                                    }
                                    if (jsonObject2.has("name")) {
                                        messageEtpConsultingDrugsEntity.setName(jsonObject2.getString("name"));
                                    }
                                    if (jsonObject2.has("norms")) {
                                        messageEtpConsultingDrugsEntity.setNorms(jsonObject2.getString("norms"));
                                    }
                                    messageEtpConsultingDrugsEntities.add(messageEtpConsultingDrugsEntity);
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {

                }
                helper.setVisible(R.id.message_etp_consulting_drugs_hint, true);
                helper.setText(R.id.message_etp_consulting_drugs_hint, "正在为您转接医生中，医生将根据您的问诊资料诊断开方");
                MessageEtpAdapter messageEtpAdapter = new MessageEtpAdapter(R.layout.message_etp_consulting_drugs_items, messageEtpConsultingDrugsEntities);
                RecyclerView recyclerView = helper.getView(R.id.message_etp_consulting_drugs);
                recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
                recyclerView.setAdapter(messageEtpAdapter);
                messageEtpAdapter.notifyDataSetChanged();
            }
            break;
            case 7026: {
                helper.setText(R.id.message_hint_center, "您的3条咨询权益已用光，请耐心等待医生回复。若您需要咨询更多问题，请点击对话框顶部【结束咨询】，确认结束咨询后可以向医生正式问诊。");
            }
            break;
            case 7027: {
                String msg = "";
                int cancelType = 1;
                if (item.getEmMessage() == null) {
                    try {
                        JSONArray jsonArray = new JSONArray(item.getCustomExt());
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            if (jsonObject.has("reason")) {
                                msg = jsonObject.getString("reason");
                            }
                            if (jsonObject.has("cancelType")) {
                                cancelType = jsonObject.getInt("cancelType");
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                } else {
                    EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
                    Map<String, String> params = body.getParams();
                    if (params.containsKey("reason")) {
                        msg = params.get("reason");
                    }
                    if (params.containsKey("cancelType")) {
                        cancelType = Integer.parseInt(params.get("cancelType"));
                    }
                }
                helper.setText(R.id.message_hint_center, cancelType == 1 ? "医生已为您退诊，退诊原因：" + msg : "患者已取消问诊，取消原因：" + msg);

            }
            break;
            case 7028:{
                helper.setText(R.id.message_patient_end_charges_hint, "温馨提示：本次问诊已到结束时间。如有新的消息，我们将第一时间通知您。");
            }
            break;
            default:
        }
    }


    private void setPrescriptionStatus(BaseViewHolder helper, ChatGroupPrescriptionStatusBean.DataBean data,boolean showStatus) {
        if (data != null) {
            helper.setVisible(R.id.message_prescription_status_img, showStatus);
            if (data.getButtonShow() == 0) {
//                处方失效不展示按钮
                helper.setVisible(R.id.message_presctiption_left_bt, false);
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_passed);
            } else if (data.getButtonShow() == 1) {
                //去预定
                helper.setVisible(R.id.message_presctiption_left_bt, true);
                helper.setText(R.id.message_presctiption_left_bt_title, "去预定");
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_finish);
            } else if (data.getButtonShow() == 2) {
                // 去支付
                helper.setVisible(R.id.message_presctiption_left_bt, true);
                helper.setText(R.id.message_presctiption_left_bt_title, "去支付");
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_used);
            } else if (data.getButtonShow() == 3) {
                // 查看订单
                helper.setVisible(R.id.message_presctiption_left_bt, true);
                helper.setText(R.id.message_presctiption_left_bt_title, "查看订单");
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_used);
            } else if (data.getButtonShow() == 4) {
                // 未下单处方审核不通打回医生修改
                helper.setVisible(R.id.message_presctiption_left_bt, false);
                helper.setText(R.id.message_presctiption_left_bt_title, "查看处方");
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_unused);
            } else if (data.getButtonShow() == 5) {
                // 未下单处方审核不通打回医生修改
                helper.setVisible(R.id.message_presctiption_left_bt, false);
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_unused);
            } else if (data.getButtonShow() == 6) {
                // 处方撤回
                helper.setVisible(R.id.message_presctiption_left_bt, false);
                helper.setImageResource(R.id.message_prescription_status_img, R.drawable.img_prescribe_unused);
            }
        } else {
            helper.setVisible(R.id.message_prescription_status_img, false);
            helper.setVisible(R.id.message_presctiption_left_bt, false);
        }
    }

    public String getStartTime_description() {
        return startTime_description;
    }

    public void setStartTime_description(String startTime_description) {
        this.startTime_description = startTime_description;
    }

    public String getEndTime_description() {
        return endTime_description;
    }

    public void setEndTime_description(String endTime_description) {
        this.endTime_description = endTime_description;
    }


    public String getRelevantDateStr() {
        return relevantDateStr;
    }

    public void setRelevantDateStr(String relevantDateStr) {
        this.relevantDateStr = relevantDateStr;
    }


    //=====================================
    void clickMessageEvaluate(HbasePatientImManagerEntity.DataBean item) {
        //评价点击
        Bundle bundle = new Bundle();
        if (item.getEmMessage() == null) {
            bundle.putInt("chargeId", item.getChargesListId());
        } else {
            EMCustomMessageBody body = (EMCustomMessageBody) item.getEmMessage().getBody();
            Map<String, String> params = body.getParams();
            if (params.containsKey("chargesListId")) {
                bundle.putInt("chargeId", Integer.parseInt(params.get("chargesListId")));
            }
        }
        MessageUtils.push(mContext,
                KitArouterConstants.IM_DOCTORBUNDLE,
                KitArouterConstants.Message.ThanksDetail,
                bundle);
    }

    class PrescriptionBean {

        /**
         * status : 200
         * data : {"ordonnanceId":7344,"orderId":"f5312860d2f24abab4755776ca439f2f","orderStatus":{"key":"paid","desc":"已支付"}}
         */

        private String status;
        /**
         * ordonnanceId : 7344
         * orderId : f5312860d2f24abab4755776ca439f2f
         * orderStatus : {"key":"paid","desc":"已支付"}
         */

        private DataBean data;

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public DataBean getData() {
            return data;
        }

        public void setData(DataBean data) {
            this.data = data;
        }

        public class DataBean {
            private int ordonnanceId;
            private String orderId;
            /**
             * key : paid
             * desc : 已支付
             */

            private OrderStatusBean orderStatus;

            public int getOrdonnanceId() {
                return ordonnanceId;
            }

            public void setOrdonnanceId(int ordonnanceId) {
                this.ordonnanceId = ordonnanceId;
            }

            public String getOrderId() {
                return orderId;
            }

            public void setOrderId(String orderId) {
                this.orderId = orderId;
            }

            public OrderStatusBean getOrderStatus() {
                return orderStatus;
            }

            public void setOrderStatus(OrderStatusBean orderStatus) {
                this.orderStatus = orderStatus;
            }

            public class OrderStatusBean {
                private String key;
                private String desc;

                public String getKey() {
                    return key;
                }

                public void setKey(String key) {
                    this.key = key;
                }

                public String getDesc() {
                    return desc;
                }

                public void setDesc(String desc) {
                    this.desc = desc;
                }
            }
        }
    }

    String timeToHms(long l, boolean isChineseUnit) {
        String t = "";
        if (l >= 3600) {
            if (isChineseUnit) {
                t = String.format("%02d", l / 60 / 60) + "时" + String.format("%02d", l / 60 % 60) + "分" + String.format("%02d", l % 60) + "秒";
            } else {
                t = String.format("%02d", l / 60 / 60) + ":" + String.format("%02d", l / 60 % 60) + ":" + String.format("%02d", l % 60);
            }
        } else if (l >= 60) {
            if (isChineseUnit) {
                t = String.format("%02d", l / 60) + "分" + String.format("%02d", l % 60) + "秒";
            } else {
                t = String.format("%02d", l / 60) + ":" + String.format("%02d", l % 60);
            }
        } else {
            if (isChineseUnit) {
                if (l < 10) {
                    t = l % 60 + "秒";
                } else {
                    t = String.format("%02d", l % 60) + "秒";
                }
            } else {
                t = String.format("%02d", l / 60) + ":" + String.format("%02d", l % 60);
            }
        }
        return t;
    }


    void toUnpaid() {
        LoadingUtils.getLoadingUtils(mContext).showLoading();

        RequestParams params = new RequestParams();
        params.put("ordonnanceId", chatprescriptiondata.getPrescriptionId() + "");
        HttpUtils.get(AllStringConstants.MessageUrl.Unpaid, params, new HttpCallBack<String>() {
            @Override
            public void onSuccess(String resultMsg, int i) {
                try {
                    if (!TextUtils.isEmpty(resultMsg)) {
                        JSONObject jsonObject = new JSONObject(resultMsg);
                        if (jsonObject.has("data") && !TextUtils.isEmpty(jsonObject.getString("data"))) {
                            JSONObject data = new JSONObject(jsonObject.getString("data"));
                            if (data.has("orderId") && !TextUtils.isEmpty(data.getString("orderId"))) {
                                Bundle bundle = new Bundle();
                                bundle.putString("id", data.getString("orderId"));
                                //MyOrderDrugDetails
                                MessageUtils.push(mContext,
                                        KitArouterConstants.MY_BUNDLE,
                                        KitArouterConstants.Mine.MyOrderDrugDetails,
                                        bundle);
                            }
                        }
                    }
                } catch (Throwable t) {

                }
                LoadingUtils.getLoadingUtils(mContext).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(mContext).dismissLoading();

            }
        });
    }

    void toNotOrder() {
        LoadingUtils.getLoadingUtils(mContext).showLoading();
        RequestParams params = new RequestParams();
        params.put("ordonnanceId", chatprescriptiondata.getPrescriptionId() + "");
        //not_order
        //expired
        HttpUtils.get(AllStringConstants.MessageUrl.createConfirm, params, new HttpCallBack<String>() {
            @Override
            public void onSuccess(String resultMsg, int i) {
                if (TextUtils.isEmpty(resultMsg)) {
                    ALog.e("数据结果为空");
                } else {
                    try {
                        JSONObject jsonObject = new JSONObject(resultMsg);
                        if (jsonObject.has("status") && jsonObject.getString("status").endsWith("Exception")) {
                            ToastUtils.showShort(jsonObject.getString("message"));
                        } else {
                            String data = jsonObject.getString("data");
                            JSONObject jsonObject1 = new JSONObject(data);
                            Bundle bundle = new Bundle();
                            if (jsonObject1.has("confirmId")) {
                                bundle.putString("id", jsonObject1.getString("confirmId"));
                            }
                            if (jsonObject1.has("dispatch")) {
                                bundle.putInt("dispatch", jsonObject1.getInt("dispatch"));
                            }
                            bundle.putString("payChartFlag", "prescribeDrug");
                            MessageUtils.push(mContext, KitArouterConstants.MY_BUNDLE, KitArouterConstants.Mine.PayChart, bundle);
                        }
                        LoadingUtils.getLoadingUtils(mContext).dismissLoading();
                    } catch (JSONException e) {
                        LoadingUtils.getLoadingUtils(mContext).dismissLoading();
                        ALog.e("数据结果解析异常");
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(String s, int i) {

            }
        });
    }
}

